﻿using Ascend;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Demo01_GettingStarted
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		#region Lifecycle
		public MainWindow()
		{
			InitializeComponent();

			// Set data context for bindings
			DataContext = this;

			// Create our Scene3D object
			//
			// A Scene3D has two main components:
			//    A camera
			//    A root SceneNode
			Scene = new Scene3D();

			// Setup the camera
			Scene.Camera.Position = new Point3D(1, 1, 3);
			Scene.Camera.LookDirection = new Vector3D(-1, -0.9, -3.1);

			// Add an object to the Scene3D by attaching a child SceneNode
			// to the root SceneNode. Only SceneNodes that are
			// attached to the root SceneNode will be rendered.
			ModelSceneNode cube = ModelSceneNode.Create(ModelMaker.MakeCube(1, 1, 1,
				Colors.DodgerBlue));
			Scene.RenderRoot.Children.Add(cube);

			// Add a few more shapes
			ModelSceneNode sphere = ModelSceneNode.Create(ModelMaker.MakeSphere(0.5,
				Colors.Purple));
			sphere.Position = new Point3D(1, 0, -0.5);
			Scene.RenderRoot.Children.Add(sphere);

			ModelSceneNode prism =
				ModelSceneNode.Create(ModelMaker.MakeCylinder(0.5, 1, 3, Colors.LimeGreen));
			prism.Position = new Point3D(-1, 0, -0.25);
			Scene.RenderRoot.Children.Add(prism);

			ModelSceneNode cylinder =
				ModelSceneNode.Create(ModelMaker.MakeCylinder(0.5, 1, Colors.Red));
			cylinder.Position = new Point3D(0, 0.25, -1);
			cylinder.ScaleY = 1.5;
			Scene.RenderRoot.Children.Add(cylinder);

			// Now add a light, so objects can be seen
			LightSceneNode light =
				LightSceneNode.Create(new DirectionalLight(Colors.White, new Vector3D(0, -1, -2)));

			// SceneNodes can be attached to other SceneNodes by either:
			//    Adding a SceneNode to another SceneNode's Children collection (the way the cube
			//    was added)
			//    Or by setting the Parent property of a SceneNode appropriately (see line below)
			light.Parent = Scene.RenderRoot;
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Gets the Scene3D that is rendered.
		/// </summary>
		public Scene3D Scene
		{
			get;
			private set;
		}
		#endregion
	}
}
